<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QDrag Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QDrag Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QDrag class provides support for MIME-based drag and drop
data transfer. <a href="#details">More...</a></p>

<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qdrag.html#QDrag">__init__</a></b> (<i>self</i>, QWidget&#160;<i>dragSource</i>)</li><li><div class="fn" />Qt.DropAction <b><a href="qdrag.html#exec">exec</a></b> (<i>self</i>, Qt.DropActions&#160;<i>supportedActions</i>, Qt.DropAction&#160;<i>defaultDropAction</i>)</li><li><div class="fn" />Qt.DropAction <b><a href="qdrag.html#exec">exec_</a></b> (<i>self</i>, Qt.DropActions&#160;<i>supportedActions</i>&#160;=&#160;Qt.MoveAction)</li><li><div class="fn" />Qt.DropAction <b><a href="qdrag.html#exec-2">exec_</a></b> (<i>self</i>, Qt.DropActions&#160;<i>supportedActions</i>, Qt.DropAction&#160;<i>defaultDropAction</i>)</li><li><div class="fn" />QPoint <b><a href="qdrag.html#hotSpot">hotSpot</a></b> (<i>self</i>)</li><li><div class="fn" />QMimeData <b><a href="qdrag.html#mimeData">mimeData</a></b> (<i>self</i>)</li><li><div class="fn" />QPixmap <b><a href="qdrag.html#pixmap">pixmap</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qdrag.html#setDragCursor">setDragCursor</a></b> (<i>self</i>, QPixmap&#160;<i>cursor</i>, Qt.DropAction&#160;<i>action</i>)</li><li><div class="fn" /><b><a href="qdrag.html#setHotSpot">setHotSpot</a></b> (<i>self</i>, QPoint&#160;<i>hotspot</i>)</li><li><div class="fn" /><b><a href="qdrag.html#setMimeData">setMimeData</a></b> (<i>self</i>, QMimeData&#160;<i>data</i>)</li><li><div class="fn" /><b><a href="qdrag.html#setPixmap">setPixmap</a></b> (<i>self</i>, QPixmap)</li><li><div class="fn" />QWidget <b><a href="qdrag.html#source">source</a></b> (<i>self</i>)</li><li><div class="fn" />Qt.DropAction <b><a href="qdrag.html#start">start</a></b> (<i>self</i>, Qt.DropActions&#160;<i>supportedActions</i>&#160;=&#160;Qt.CopyAction)</li><li><div class="fn" />QWidget <b><a href="qdrag.html#target">target</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qdrag.html#actionChanged">actionChanged</a></b> (Qt::DropAction)</li><li><div class="fn" />void <b><a href="qdrag.html#targetChanged">targetChanged</a></b> (QWidget *)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QDrag class provides support for MIME-based drag and drop
data transfer.</p>
<p>Drag and drop is an intuitive way for users to copy or move data
around in an application, and is used in many desktop environments
as a mechanism for copying data between applications. Drag and drop
support in Qt is centered around the QDrag class that handles most
of the details of a drag and drop operation.</p>
<p>The data to be transferred by the drag and drop operation is
contained in a <a href="qmimedata.html">QMimeData</a> object. This
is specified with the <a href="qdrag.html#setMimeData">setMimeData</a>() function in the
following way:</p>
<pre class="cpp">
         <span class="type">QDrag</span> <span class="operator">*</span>drag <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QDrag</span>(<span class="keyword">this</span>);
         <span class="type"><a href="qmimedata.html">QMimeData</a></span> <span class="operator">*</span>mimeData <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qmimedata.html">QMimeData</a></span>;

         mimeData<span class="operator">-</span><span class="operator">&gt;</span>setText(commentEdit<span class="operator">-</span><span class="operator">&gt;</span>toPlainText());
         drag<span class="operator">-</span><span class="operator">&gt;</span>setMimeData(mimeData);
</pre>
<p>Note that <a href="qdrag.html#setMimeData">setMimeData</a>()
assigns ownership of the <a href="qmimedata.html">QMimeData</a>
object to the QDrag object. The QDrag must be constructed on the
heap with a parent <a href="qwidget.html">QWidget</a> to ensure
that Qt can clean up after the drag and drop operation has been
completed.</p>
<p>A pixmap can be used to represent the data while the drag is in
progress, and will move with the cursor to the drop target. This
pixmap typically shows an icon that represents the MIME type of the
data being transferred, but any pixmap can be set with <a href="qdrag.html#setPixmap">setPixmap</a>(). The cursor's hot spot can
be given a position relative to the top-left corner of the pixmap
with the <a href="qdrag.html#setHotSpot">setHotSpot</a>() function.
The following code positions the pixmap so that the cursor's hot
spot points to the center of its bottom edge:</p>
<pre class="cpp">
     drag<span class="operator">-</span><span class="operator">&gt;</span>setHotSpot(<span class="type"><a href="qpoint.html">QPoint</a></span>(drag<span class="operator">-</span><span class="operator">&gt;</span>pixmap()<span class="operator">.</span>width()<span class="operator">/</span><span class="number">2</span><span class="operator">,</span>
                             drag<span class="operator">-</span><span class="operator">&gt;</span>pixmap()<span class="operator">.</span>height()));
</pre>
<p><b>Note:</b> On X11, the pixmap may not be able to keep up with
the mouse movements if the hot spot causes the pixmap to be
displayed directly under the cursor.</p>
<p>The source and target widgets can be found with <a href="qdrag.html#source">source</a>() and <a href="qdrag.html#target">target</a>(). These functions are often used to
determine whether drag and drop operations started and finished at
the same widget, so that special behavior can be implemented.</p>
<p>QDrag only deals with the drag and drop operation itself. It is
up to the developer to decide when a drag operation begins, and how
a QDrag object should be constructed and used. For a given widget,
it is often necessary to reimplement <a href="qwidget.html#mousePressEvent">mousePressEvent()</a> to determine
whether the user has pressed a mouse button, and reimplement
<a href="qwidget.html#mouseMoveEvent">mouseMoveEvent()</a> to check
whether a QDrag is required.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QDrag" />QDrag.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>dragSource</i>)</h3><p>The <i>dragSource</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a new drag object for the widget specified by
<i>dragSource</i>.</p>


<h3 class="fn"><a name="exec" /><a href="qt.html#DropAction-enum">Qt.DropAction</a> QDrag.exec (<i>self</i>, <a href="qt-dropactions.html">Qt.DropActions</a>&#160;<i>supportedActions</i>, <a href="qt.html#DropAction-enum">Qt.DropAction</a>&#160;<i>defaultDropAction</i>)</h3><p>Starts the drag and drop operation and returns a value
indicating the requested drop action when it is completed. The drop
actions that the user can choose from are specified in
<i>supportedActions</i>. The default proposed action will be
selected among the allowed actions in the following order: Move,
Copy and Link.</p>
<p><b>Note:</b> On Linux and Mac OS X, the drag and drop operation
can take some time, but this function does not block the event
loop. Other events are still delivered to the application while the
operation is performed. On Windows, the Qt event loop is blocked
while during the operation.</p>
<p>This function was introduced in Qt 4.3.</p>


<h3 class="fn"><a name="exec" /><a href="qt.html#DropAction-enum">Qt.DropAction</a> QDrag.exec_ (<i>self</i>, <a href="qt-dropactions.html">Qt.DropActions</a>&#160;<i>supportedActions</i>&#160;=&#160;Qt.MoveAction)</h3><p>Starts the drag and drop operation and returns a value
indicating the requested drop action when it is completed. The drop
actions that the user can choose from are specified in
<i>supportedActions</i>. The default proposed action will be
selected among the allowed actions in the following order: Move,
Copy and Link.</p>
<p><b>Note:</b> On Linux and Mac OS X, the drag and drop operation
can take some time, but this function does not block the event
loop. Other events are still delivered to the application while the
operation is performed. On Windows, the Qt event loop is blocked
while during the operation.</p>
<p>This function was introduced in Qt 4.3.</p>


<h3 class="fn"><a name="exec-2" /><a href="qt.html#DropAction-enum">Qt.DropAction</a> QDrag.exec_ (<i>self</i>, <a href="qt-dropactions.html">Qt.DropActions</a>&#160;<i>supportedActions</i>, <a href="qt.html#DropAction-enum">Qt.DropAction</a>&#160;<i>defaultDropAction</i>)</h3><p>Starts the drag and drop operation and returns a value
indicating the requested drop action when it is completed. The drop
actions that the user can choose from are specified in
<i>supportedActions</i>.</p>
<p>The <i>defaultDropAction</i> determines which action will be
proposed when the user performs a drag without using modifier
keys.</p>
<p><b>Note:</b> On Linux and Mac OS X, the drag and drop operation
can take some time, but this function does not block the event
loop. Other events are still delivered to the application while the
operation is performed. On Windows, the Qt event loop is blocked
during the operation. However, <a href="qdrag.html#exec">QDrag.exec</a>() on Windows causes
processEvents() to be called frequently to keep the GUI responsive.
If any loops or operations are called while a drag operation is
active, it will block the drag operation.</p>
<p>This function was introduced in Qt 4.3.</p>


<h3 class="fn"><a name="hotSpot" /><a href="qpoint.html">QPoint</a> QDrag.hotSpot (<i>self</i>)</h3><h3 class="fn"><a name="mimeData" /><a href="qmimedata.html">QMimeData</a> QDrag.mimeData (<i>self</i>)</h3><p>Returns the MIME data that is encapsulated by the drag
object.</p>
<p><b>See also</b> <a href="qdrag.html#setMimeData">setMimeData</a>().</p>


<h3 class="fn"><a name="pixmap" /><a href="qpixmap.html">QPixmap</a> QDrag.pixmap (<i>self</i>)</h3><p>Returns the pixmap used to represent the data in a drag and drop
operation.</p>
<p><b>See also</b> <a href="qdrag.html#setPixmap">setPixmap</a>().</p>


<h3 class="fn"><a name="setDragCursor" />QDrag.setDragCursor (<i>self</i>, <a href="qpixmap.html">QPixmap</a>&#160;<i>cursor</i>, <a href="qt.html#DropAction-enum">Qt.DropAction</a>&#160;<i>action</i>)</h3><p>Sets the drag <i>cursor</i> for the <i>action</i>. This allows
you to override the default native cursors. To revert to using the
native cursor for <i>action</i> pass in a null <a href="qpixmap.html">QPixmap</a> as <i>cursor</i>.</p>
<p>The <i>action</i> can only be CopyAction, MoveAction or
LinkAction. All other values of DropAction are ignored.</p>


<h3 class="fn"><a name="setHotSpot" />QDrag.setHotSpot (<i>self</i>, <a href="qpoint.html">QPoint</a>&#160;<i>hotspot</i>)</h3><p>Sets the position of the hot spot relative to the top-left
corner of the pixmap used to the point specified by
<i>hotspot</i>.</p>
<p><b>Note:</b> on X11, the pixmap may not be able to keep up with
the mouse movements if the hot spot causes the pixmap to be
displayed directly under the cursor.</p>
<p><b>See also</b> <a href="qdrag.html#hotSpotx">hotSpot</a>().</p>


<h3 class="fn"><a name="setMimeData" />QDrag.setMimeData (<i>self</i>, <a href="qmimedata.html">QMimeData</a>&#160;<i>data</i>)</h3><p>The <i>data</i> argument has it's ownership transferred to Qt.</p><p>Sets the data to be sent to the given MIME <i>data</i>.
Ownership of the data is transferred to the <a href="qdrag.html">QDrag</a> object.</p>
<p><b>See also</b> <a href="qdrag.html#mimeData">mimeData</a>().</p>


<h3 class="fn"><a name="setPixmap" />QDrag.setPixmap (<i>self</i>, <a href="qpixmap.html">QPixmap</a>)</h3><p>Sets <i>pixmap</i> as the pixmap used to represent the data in a
drag and drop operation. You can only set a pixmap before the drag
is started.</p>
<p><b>See also</b> <a href="qdrag.html#pixmap">pixmap</a>().</p>


<h3 class="fn"><a name="source" /><a href="qwidget.html">QWidget</a> QDrag.source (<i>self</i>)</h3><p>Returns the source of the drag object. This is the widget where
the drag and drop operation originated.</p>


<h3 class="fn"><a name="start" /><a href="qt.html#DropAction-enum">Qt.DropAction</a> QDrag.start (<i>self</i>, <a href="qt-dropactions.html">Qt.DropActions</a>&#160;<i>supportedActions</i>&#160;=&#160;Qt.CopyAction)</h3><h3 class="fn"><a name="target" /><a href="qwidget.html">QWidget</a> QDrag.target (<i>self</i>)</h3><p>Returns the target of the drag and drop operation. This is the
widget where the drag object was dropped.</p>


<hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="actionChanged" />void actionChanged (Qt::DropAction)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when the <i>action</i> associated with
the drag changes.</p>
<p><b>See also</b> <a href="qdrag.html#targetChanged">targetChanged</a>().</p>


<h3 class="fn"><a name="targetChanged" />void targetChanged (QWidget *)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted when the target of the drag and drop
operation changes, with <i>newTarget</i> the new target.</p>
<p><b>See also</b> <a href="qdrag.html#target">target</a>() and
<a href="qdrag.html#actionChanged">actionChanged</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;snapshot-4.9.5-9eb6aac99275 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.3</td></tr></table></div></address></body></html>